package prolog.terms

import scala.collection.mutable._


import prolog.fluents.HashDict


class VarNumberer extends SystemObject {
  val dict = new LinkedHashMap[Term, Term]()
  var ctr: Int = 0


  override def action(place: Term): Term = {
    var place2 = place.ref
    // IO.trace(">>action: "+place)
    if (place2.isInstanceOf[Var]) {
      var root: Const = dict.get(place2).asInstanceOf[Const]
      if (null == root) {
        root = new PseudoVar(ctr + 1)
        dict.put(place2, root)
      }
      place2 = root
    }
    // IO.trace("<<action: "+place)
    place2
  }
}
